import java.io.FileWriter;
import java.io.IOException;

public class DataExporter {
    private DormitorySystem system;

    public DataExporter(DormitorySystem system) {
        this.system = system;
    }

    // 导出住宿信息
    public void exportData() {
        try {
            FileWriter writer = new FileWriter("住宿信息.txt");

            for (Room room : system.getRooms()) {
                writer.write("房间号: " + room.getRoomNumber() + "\n");
                for (int i = 0; i < room.getBeds().length; i++) {
                    Student student = room.getBeds()[i];
                    if (student != null) {
                        writer.write("  床位 " + (i + 1) + ": " + student.getName() + " (学号: " + student.getId() + ")\n");
                    } else {
                        writer.write("  床位 " + (i + 1) + ": 空闲\n");
                    }
                }
            }

            writer.close();
            System.out.println("住宿信息已导出");
        } catch (IOException e) {
            System.out.println("导出失败: " + e.getMessage());
        }
    }
}
